package com.ysd.lis.controller.sys;

import com.ysd.common.dto.OrganizationDTO;
import com.ysd.lis.annotation.LogDetail;
import com.ysd.lis.aspect.OperationType;
import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.request.RolePageParam;
import com.ysd.lis.request.SysRoleDetailsParam;
import com.ysd.lis.request.roleAddParam;
import com.ysd.lis.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * cold_chain.t_role 前端控制器
 * </p>
 *
 * @author bai
 * @since 2023-10-08
 */
@Api(tags = "权限角色管理")
@RestController
public class SysRoleController extends BaseController {

    @Autowired
    SysRoleService sysRoleService;

    @ApiOperation("查询角色列表（不分页）")
    @GetMapping("/api/sys/findRoleList")
    public Result getList() {
        return sysRoleService.findRoleList();
    }
    @ApiOperation("查询角色列表（新数据接口）")
    @GetMapping("/api/sys/getRoleList")
    public Result getRoleList() {
        return sysRoleService.getRoleList();
    }

    @ApiOperation("查询角色列表（分页）")
    @GetMapping("/api/sys/findRolePageList")
    public Result findRolePageList( RolePageParam pageParam) {
        return sysRoleService.findRolePageList(pageParam);
    }

    @ApiOperation("获取权限")
    @GetMapping("/api/sys/findClassPermissionList")
    public Result findClassPermissionList() {
        return sysRoleService.getPermission();
    }

    @ApiOperation("添加角色")
    @PostMapping("/api/sys/addRole")
    @LogDetail(requestParam ="addRole",operationType = OperationType.INSERT, module = "角色管理",content = "通过系统管理模块，使用角色管理新增了：【roleName】角色")
    public Result addRole(@RequestBody roleAddParam role) {
        return sysRoleService.addRole(role);
    }

    @ApiOperation("删除角色")
    @DeleteMapping("/api/sys/deleteRole/{id}")
    @LogDetail(requestParam ="deleteRole",operationType = OperationType.DELETE, module = "角色管理",content = "删除角色操作")
    public Result deleteRole(@PathVariable("id") String id) {
        return sysRoleService.deleteRole(id);
    }

    @ApiOperation("获取角色单条信息")
    @GetMapping("/api/sys/findRoleInfo")
    public Result findRoleInfo(String id) {
        return sysRoleService.findRoleInfo(id);
    }

    @ApiOperation("修改角色信息")
    @PostMapping("/api/sys/editRole")
    @LogDetail(requestParam ="editRole",operationType = OperationType.UPDATE, module = "角色管理",content = "修改角色操作")
    public Result editRole(@RequestBody roleAddParam role) {
        return sysRoleService.editRole(role);
    }

    @ApiOperation("根据模块Id获取当前菜单与功能点")
    @PostMapping("/api/sys/getMenuAndPointsByMouldId")
    public Result getMenuAndPointsByMouldId(@RequestBody SysRoleDetailsParam sysRoleDetailsParam) {
        return sysRoleService.getMenuAndPointsByMouldId(sysRoleDetailsParam);
    }
    @ApiOperation("根据角色获取角色下模块信息")
    @PostMapping("/api/sys/getRoleAndModuleByRoleId")
    public Result getRoleAndModuleByRoleId(@RequestBody SysRoleDetailsParam sysRoleDetailsParam) {

        return sysRoleService.getRoleAndModuleByRoleId(sysRoleDetailsParam);
    }
    @ApiOperation("根据选中的模块id更新角色信息")
    @PostMapping("/api/sys/saveRoleByModuleId")
    public Result saveRoleByModuleId(@RequestBody roleAddParam role) {
        return sysRoleService.saveRoleByModuleIds(role);
    }

    @ApiOperation("根据取消选中的模块id更新角色信息")
    @PostMapping("/api/sys/deleteRoleByModuleId")
    public Result deleteRoleByModuleId(@RequestBody roleAddParam role) {
        return sysRoleService.deleteRoleByModuleId(role);
    }
    @ApiOperation("拼量勾选菜单操作")
    @PostMapping("/api/sys/saveBatchRoleMenu")
    @LogDetail(requestParam ="saveBatchRoleMenu",operationType = OperationType.INSERT, module = "角色管理",content = "批量勾选分配角色菜单操作")
    public Result saveBatchRoleMenu(@RequestBody List<roleAddParam> roles) {
        return sysRoleService.saveRoleMenu(roles);
    }

    @ApiOperation("勾选菜单操作")
    @PostMapping("/api/sys/saveRoleMenu")
    @LogDetail(requestParam ="saveRoleMenu",operationType = OperationType.INSERT, module = "角色管理",content = "分配角色菜单操作")
    public Result saveRoleMenu(@RequestBody roleAddParam role) {
        return sysRoleService.saveRoleMenu(role);
    }
    @ApiOperation("取消勾选菜单操作")
    @PostMapping("/api/sys/deleteRoleMenu")
    @LogDetail(requestParam ="deleteRoleMenu",operationType = OperationType.DELETE, module = "角色管理",content = "取消角色菜单操作")
    public Result deleteRoleMenu(@RequestBody roleAddParam role) {
        return sysRoleService.deleteRoleMenu(role);
    }


    @ApiOperation("勾选功能操作")
    @PostMapping("/api/sys/saveRolePoint")
    @LogDetail(requestParam ="saveRolePoint",operationType = OperationType.INSERT, module = "角色管理",content = "分配角色功能点操作")
    public Result saveRolePoint(@RequestBody roleAddParam role) {
        return sysRoleService.saveRolePoint(role);
    }
    @ApiOperation("取消勾选功能操作")
    @PostMapping("/api/sys/deleteRolePoint")
    @LogDetail(requestParam ="deleteRolePoint",operationType = OperationType.DELETE, module = "角色管理",content = "取消角色功能点操作 ")
    public Result deleteRolePoint(@RequestBody roleAddParam role) {
        return sysRoleService.deleteRolePoint(role);
    }
    @ApiOperation("获取权限详情")
    @PostMapping("/api/sys/getRoleDetailsList")
    public Result getRoleDetails(@RequestBody SysRoleDetailsParam roleDetailsParam) {
        return sysRoleService.getRoleDetails(roleDetailsParam);
    }












}
